Skip to content

fix(devtools): keep source line numbers when instrumenting components - #9153

Merged
maiieul merged 2 commits into
QwikDev:mainfrom
Aejkatappaja:fix/devtools-instrumentation-line-numbers
Oct 6, 2026
Merged

maiieul merged 2 commits into
QwikDev:mainfrom
Aejkatappaja:fix/devtools-instrumentation-line-numbers

Conversation

@Aejkatappaja

@Aejkatappaja Aejkatappaja commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

What is it?

  • Bug

Description

With qwikDevtools() or qwikMcp() enabled, Alt+click (click-to-source) opens the editor several lines below the element you clicked. On the MCP SSR fixture the counter button is on line 5 of routes/index.tsx, and data-qwik-inspector says routes/index.tsx:14:5, past the end of a 10 line file. Without either plugin it says 5:5.

Both plugins instrument component files (and DevTools also root.tsx) in a pre transform, before the Qwik optimizer: an import at the top, const collecthook = ... at the start of each component, a multi-line collecthook({...}) after every hook, and <QwikDevtools /> before </body>. Every one of those added lines. The optimizer computes dev locations from the text it receives and takes no input sourcemap, so returning a sourcemap from the transform wouldn't help here.

The fix keeps the instrumentation but never adds a line: the imports go on line 1, the init goes right after the component's {, each collecthook(...) is appended on its hook's line (with a ; when the statement relies on ASI), and <QwikDevtools /> sits right before </body>. The rule is written next to both transform hooks so it doesn't regress.

What it doesn't fix:

  • columns can still be off on a line that got an insertion, e.g. JSX on the same line as the component's opening {
  • QRLDev lo/hi are byte offsets, so they still move. Getting those right would mean instrumenting after the optimizer, which is a bigger change

There's also a separate one-line commit fixing the type of the birpc resolver from #9123, which made @qwik.dev/mcp fail its typecheck.

Tests: a unit test checks that both transforms keep every source line on its line number and still parse, and the MCP integration test now asserts data-qwik-inspector ends with routes/index.tsx:5:5. That assertion fails on main with 14:5.

Demo

Alt+click on the same button, before and after. The banner shows the location the editor was asked to open and what is actually on that line.

devtools-click-to-source-lines.mp4

Checklist

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I added new tests to cover the fix / functionality

The resolver used birpc's default generics, which don't match the RPC's own, so @qwik.dev/mcp failed to typecheck. Our resolver ignores this, so BirpcResolver<unknown> fits every caller.
DevTools and MCP instrument component files and root.tsx before the Qwik optimizer, which takes no input sourcemap. Every inserted line shifted the locations it computes, so data-qwik-inspector (click-to-source) pointed several lines below the element. Insert everything inline so source lines stay where they are.
@Aejkatappaja
Aejkatappaja requested a review from a team as a code owner October 4, 2026 21:22
@changeset-bot

changeset-bot Bot commented Oct 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 571796f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@qwik.dev/devtools Patch
@qwik.dev/mcp Patch
create-qwik Patch
eslint-plugin-qwik Patch
@qwik.dev/react Patch
@qwik.dev/router Patch
@qwik.dev/utils Patch
@qwik.dev/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@9153

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@9153

@qwik.dev/utils

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/utils@9153

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@9153

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@9153

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@9153

@qwik.dev/devtools

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/devtools@9153

@qwik.dev/mcp

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/mcp@9153

commit: 571796f

@maiieul
maiieul merged commit f09cdf4 into QwikDev:main Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants